<template>
  <div class="meeting-add-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>新增会议</span>
          <el-button @click="goBack">返回</el-button>
        </div>
      </template>
      
      <el-form :model="meetingForm" :rules="rules" ref="meetingFormRef" label-width="100px">
        <el-form-item label="会议主题" prop="title">
          <el-input v-model="meetingForm.title" placeholder="请输入会议主题" />
        </el-form-item>
        
        <el-form-item label="主持人" prop="host">
          <el-input v-model="meetingForm.host" placeholder="请输入主持人姓名" />
        </el-form-item>
        
        <el-form-item label="会议时间" prop="time">
          <el-date-picker
            v-model="meetingForm.time"
            type="datetime"
            placeholder="请选择会议时间"
            style="width: 100%"
            value-format="YYYY-MM-DD HH:mm:ss"
          />
        </el-form-item>
        
        <el-form-item label="会议地点" prop="location">
          <el-input v-model="meetingForm.location" placeholder="请输入会议地点" />
        </el-form-item>
        
        <el-form-item label="参会人员" prop="participants">
          <el-select 
            v-model="meetingForm.participants" 
            multiple 
            filterable 
            allow-create 
            default-first-option
            placeholder="请选择或输入参会人员"
            style="width: 100%"
          >
            <el-option label="张三" value="张三" />
            <el-option label="李四" value="李四" />
            <el-option label="王五" value="王五" />
            <el-option label="赵六" value="赵六" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="会议描述" prop="description">
          <el-input 
            v-model="meetingForm.description" 
            type="textarea" 
            placeholder="请输入会议描述"
            :rows="4"
          />
        </el-form-item>
        
        <el-form-item label="上传音频" prop="audioFiles">
          <el-upload
            class="audio-uploader"
            action="#"
            :auto-upload="false"
            :file-list="audioFileList"
            multiple
          >
            <el-button type="primary">选择音频文件</el-button>
            <template #tip>
              <div class="el-upload__tip">
                支持mp3、wav、flac格式，单个文件不超过100MB
              </div>
            </template>
          </el-upload>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

export default {
  name: 'MeetingAdd',
  setup() {
    const router = useRouter()
    const meetingFormRef = ref(null)
    
    const meetingForm = reactive({
      title: '',
      host: '',
      time: '',
      location: '',
      participants: [],
      description: '',
      audioFiles: []
    })
    
    const audioFileList = ref([])
    
    const rules = {
      title: [
        { required: true, message: '请输入会议主题', trigger: 'blur' }
      ],
      host: [
        { required: true, message: '请输入主持人姓名', trigger: 'blur' }
      ],
      time: [
        { required: true, message: '请选择会议时间', trigger: 'change' }
      ],
      location: [
        { required: true, message: '请输入会议地点', trigger: 'blur' }
      ]
    }
    
    const submitForm = async () => {
      if (!meetingFormRef.value) return
      
      await meetingFormRef.value.validate((valid) => {
        if (valid) {
          // 模拟提交操作
          ElMessage.success('会议添加成功')
          router.push('/meetings')
        } else {
          ElMessage.error('请填写完整信息')
        }
      })
    }
    
    const resetForm = () => {
      meetingFormRef.value.resetFields()
      audioFileList.value = []
    }
    
    const goBack = () => {
      router.go(-1)
    }
    
    return {
      meetingFormRef,
      meetingForm,
      audioFileList,
      rules,
      submitForm,
      resetForm,
      goBack
    }
  }
}
</script>

<style scoped>
.meeting-add-container {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.audio-uploader {
  width: 100%;
}
</style>